package cn.cqs.redisitem.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

//RestController 相当于@ReposeBody+@Controller
//@RestController
public class RedisController {
// todo   @Autowired
    private StringRedisTemplate redisTemplate;
//  todo  @Autowired
    private RedisTemplate<String, Object> redisCasheTemplate;
//    @Autowired
//    private RespositoryBook respositoryBook;

    @RequestMapping(value = "/get", method = RequestMethod.GET)

    public String getUrl() {
        redisTemplate.opsForValue().set("name", "hongjuang");
        System.out.println(redisTemplate.opsForValue().get("name"));
        return "my name is cao qi shun";
    }

    @RequestMapping(value = "/getlist", method = RequestMethod.GET)
    public List getUserList(String param) {
        String key = "flow:list";
        String[] params = param.split(",");
        for (String s : params) {
//            redis
            System.out.println(redisCasheTemplate.type(key));
            redisCasheTemplate.opsForList().rightPush(key,s);
        }
        List list=redisCasheTemplate.opsForList().range(key, 0, -1);
        return list;
    }
//       @GetMapping(value = "/booklist")
//    public List<Book> getbooks(){
//        return respositoryBook.findAll();
//    }


}
